<?php
/**
 * lsys task
 * @author     Lonely <shan.liu@msn.com>
 * @copyright  (c) 2017 Lonely <shan.liu@msn.com>
 * @license    http://www.apache.org/licenses/LICENSE-2.0
 */
if(PHP_SAPI!='cli')die('plase run in cli');
if(DIRECTORY_SEPARATOR == '\\')die("plase run in unix");
if (!function_exists('pcntl_fork')) die('plase install pcntl ext');
if (!defined('LSYS_CRON_DISPATCHER_PATH')||!defined('LSYS_CRON_RUNER_PATH'))
	die('plase defind LSYS_CRON_DISPATCHER_PATH and LSYS_CRON_RUNER_PATH const');
require_once __DIR__.'/unix_user.php';
$run=$dis=0;
if (!$dis){
	label_dis:
	$pid = pcntl_fork();
	if ($pid == -1) die(pcntl_get_last_error());
	else if ($pid) {
		unset($dis);
		$dis=$pid;
	}else{
		unset($run,$dis,$pid);
		goto dis;
	}
}
if (!$run){
	label_run:
	$pid = pcntl_fork();
	if ($pid == -1) die(pcntl_get_last_error());
	else if ($pid) {
		unset($run);
		$run=$pid;
	}else{
		unset($run,$dis,$pid);
		goto run;
	}
}
//wait child end..
$pid=pcntl_wait($status,WUNTRACED);
if ($pid==$dis) goto label_dis;
if ($pid==$run) goto label_run;
exit('over');
dis:
include LSYS_CRON_DISPATCHER_PATH;
exit;
run:
include LSYS_CRON_RUNER_PATH;
exit;